package com.yx.yinshanjinniu.net;

import android.content.Context;
import android.text.TextUtils;

import com.google.gson.Gson;
import com.umeng.commonsdk.UMConfigure;
import com.umeng.commonsdk.listener.OnGetOaidListener;
import com.yx.yinshanjinniu.BuildConfig;
import com.yx.yinshanjinniu.application.MyApplication;
import com.yx.yinshanjinniu.constants.Constant;
import com.yx.yinshanjinniu.eventbus.EventConstants;
import com.yx.yinshanjinniu.eventbus.EventCenter;
import com.yx.yinshanjinniu.utils.DataTimeUtils;
import com.yx.yinshanjinniu.utils.DataUtils;
import com.yx.yinshanjinniu.utils.LogUtil;
import com.yx.yinshanjinniu.utils.NetCheckUtil;
import com.yx.yinshanjinniu.utils.StringUtil;
import com.yx.yinshanjinniu.utils.Utils;

import org.greenrobot.eventbus.EventBus;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.IOException;
import java.security.KeyStore;
import java.security.SecureRandom;
import java.security.cert.CertificateFactory;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.concurrent.TimeUnit;

import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession;
import javax.net.ssl.TrustManagerFactory;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.Headers;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;

/**
 * Created by Administrator on 2017/5/2 0002.
 */

public class OkHttpEngine {
    private OkHttpClient mOkHttpClient;//懒加载

    private final static String JSON = "application/json; charset=utf-8";
    private static OkHttpEngine mInstance = null;
    private Gson mGson;
    private Context mContext;
    public static String APP_ID = "10003";

    public static OkHttpEngine getInstance(Context context) {
        if (mInstance == null) {
            synchronized (OkHttpEngine.class) {
                if (mInstance == null) {
                    mInstance = new OkHttpEngine(context);
                }
            }
        }
        return mInstance;
    }

    /**
     * http配置
     *
     * @param context
     */
    private OkHttpEngine(Context context) {
        mContext = context;
        mOkHttpClient = new OkHttpClient().newBuilder()
                .connectTimeout(Constant.TIME_OUT, TimeUnit.MILLISECONDS)
                .readTimeout(Constant.TIME_OUT, TimeUnit.MILLISECONDS).build();
//        mOkHttpClient = setCertificate();
        mGson = new Gson();
    }

    /**
     * https配置
     *
     * @return
     */
    private OkHttpClient setCertificate() {
        OkHttpClient.Builder builder = new OkHttpClient.Builder()
                .addInterceptor(chain -> {
                            long startTime = System.currentTimeMillis();
                            okhttp3.Response response = chain.proceed(chain.request());
                            long endTime = System.currentTimeMillis();
                            long duration = endTime - startTime;
                            String requestMethod = chain.request().method();
                            String requestUrl = chain.request().url().toString();

                            // 打印请求时间和URL
                            LogUtil.d("dangzt", requestMethod + " " + requestUrl + " took " + duration + " ms");

                            return response;})
                .connectTimeout(Constant.TIME_OUT, TimeUnit.MILLISECONDS)
                .readTimeout(Constant.TIME_OUT, TimeUnit.MILLISECONDS);
        try {
            CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509");
            KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
            keyStore.load(null);
            String certificateAlias = Integer.toString(0);
            keyStore.setCertificateEntry(certificateAlias, certificateFactory.generateCertificate(mContext.getAssets().open("fenghuang.crt")));//拷贝好的证书
            SSLContext sslContext = SSLContext.getInstance("TLS");
            final TrustManagerFactory trustManagerFactory =
                    TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
            trustManagerFactory.init(keyStore);
            sslContext.init
                    (
                            null,
                            trustManagerFactory.getTrustManagers(),
                            new SecureRandom()
                    );
            builder.sslSocketFactory(sslContext.getSocketFactory());
            builder.hostnameVerifier(new HostnameVerifier() {
                @Override
                public boolean verify(String s, SSLSession sslSession) {
                    return true;
                }
            });
        } catch (Exception e) {
            e.printStackTrace();
        }
        return builder.build();
    }

    /**
     * post请求
     *
     * @param paramsMap 请求参数
     * @param method    url拼接
     * @param callBack  回调
     */
    public void postAsync(Map<String, Object> paramsMap, String method, final ApiCallBack<String> callBack) {
        if (method.equals("index/ad_post")){
            LogUtil.e("dangzt", "开始请求");
        }
        if (!NetCheckUtil.isNetConnected(mContext)) {
            callBack.onFailure(Constant.NO_NETWORK, Constant.NO_NETWORK_MSG);
            return;
        }

        if (StringUtil.isEmpty(DataUtils.getOAID(mContext))){
            UMConfigure.getOaid(MyApplication.getApplication(), new OnGetOaidListener() {
                @Override
                public void onGetOaid(String s) {
                    if (!TextUtils.isEmpty(s)) {
                        DataUtils.setOAID(mContext, s);
                        LogUtil.d("dangzt", "oaid=====" + DataUtils.getOAID(mContext));

                        toRealRequest(paramsMap, method, callBack);
                    }else {
                        DataUtils.setOAID(mContext, System.currentTimeMillis() + "-" + new Random().nextInt(99999) + 10000 + "-" + new Random().nextInt(99999) + 10000);
                        LogUtil.d("dangzt", "oaid=====" + DataUtils.getOAID(mContext));

                        toRealRequest(paramsMap, method, callBack);
                    }
                }
            });
        }else {
            toRealRequest(paramsMap, method, callBack);
        }
    }

    private void toRealRequest(Map<String, Object> paramsMap, String method, final ApiCallBack<String> callBack){
        //设置body
        JSONObject body = new JSONObject();
        try {
            if (null != paramsMap) {
                for (String key : paramsMap.keySet()) {
                    if (paramsMap.get(key) instanceof List) {
                        ArrayList mList = (ArrayList) paramsMap.get(key);
                        JSONArray array = new JSONArray();
                        for (Object m : mList) {
                            array.put(m);
                        }
                        body.put(key, array);
                    } else {
                        body.put(key, paramsMap.get(key));
                    }
                }
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
        RequestBody requestBody = RequestBody.create(MediaType.parse(JSON), body.toString());

        //设置header
        // 添加公共参数到header
        JSONObject main = new JSONObject();
        try {
            main.put("app_id", Constant.APP_ID);
            main.put("client_id", DataUtils.getClientId(mContext));
            main.put("oaid", DataUtils.getOAID(mContext));
            main.put("timestamp", DataTimeUtils.getTimeStamp());
            main.put("user_id", DataUtils.getUserId(mContext));
            main.put("uuid", DataUtils.getUUID(mContext));
            main.put("version", Utils.getVersion(mContext));
            if (TextUtils.isEmpty(DataUtils.getToken(mContext))) {
                main.put("key", DataUtils.getSignKey(mContext));
            } else {
                main.put("key", DataUtils.getToken(mContext));
            }
        } catch (JSONException e) {
            throw new RuntimeException(e);
        }

        Headers.Builder headerBuild = new Headers.Builder();
        headerBuild.add("app_id", Constant.APP_ID);
        headerBuild.add("client_id", DataUtils.getClientId(mContext));
        headerBuild.add("oaid", DataUtils.getOAID(mContext));
        headerBuild.add("timestamp", DataTimeUtils.getTimeStamp());
        headerBuild.add("user_id", DataUtils.getUserId(mContext));
        headerBuild.add("uuid", DataUtils.getUUID(mContext));
        headerBuild.add("version", Utils.getVersion(mContext));
        headerBuild.add("token", jsonToStringToMd5(main));
        Headers headers = headerBuild.build();

        //设置url
        final String url = (BuildConfig.SERVER_TYPE.equals("prod") ? Constant.SERVER_URL : Constant.DEV_SERVER_URL) + method;

        //设置request
        final Request request = new Request.Builder()
                .url(url)
                .post(requestBody)
                .headers(headers)
                .build();
        LogUtil.d("url = " + url + " ====header = " + headers.toString());
        LogUtil.d("url = " + url + " ====json = " + body.toString());

        //发起请求
        mOkHttpClient.newCall(request).enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                callBack.onFailure(Constant.FAILED, Constant.TIME_OUT_EVENT_MSG);
            }

            @Override
            public void onResponse(Call call, Response response) {
                try {
                    String str = response.body().string();
                    LogUtil.d("url = " + url + "  = " + str);
                    JSONObject jsonObject = new JSONObject(str);
                    String code = "";
                    try {
                        code = jsonObject.getString("code");
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                    if (code == null || code.isEmpty()) {
                        callBack.onFailure(Constant.FAILED, Constant.TIME_OUT_EVENT_MSG);
                    } else if (code.equals("200")) {
                        callBack.onSuccess(str);
                    } else if (code.equals("403")) {
                        callBack.onFailure(code, jsonObject.getString("msg"));
                        //清除用户登录信息
                        DataUtils.clearUserInfo(mContext);
                        //发送token过期事件
                        EventBus.getDefault().post(new EventCenter(EventConstants.EVENTCODE_TOKEN_ERRO));
                    } else {
                        callBack.onFailure(code, jsonObject.getString("msg"));
                    }
//                    }
                } catch (Exception e) {
                    e.printStackTrace();
                    callBack.onFailure(Constant.FAILED, Constant.TIME_OUT_EVENT_MSG);
                }
            }
        });
    }

    void getAsync(final String url, final ApiCallBack<String> callBack) {
        if (!NetCheckUtil.isNetConnected(mContext)) {
            callBack.onFailure(Constant.NO_NETWORK, Constant.NO_NETWORK_MSG);
            return;
        }
        LogUtil.d("url = " + url);
        Headers.Builder headerBuild = new Headers.Builder();
        headerBuild.add("x-app-id", "g93rhHb9DcDptypd");
        headerBuild.add("x-version", "2.0");
        Headers headers = headerBuild.build();
        Request request = new Request.Builder().url(url).headers(headers).build();
        mOkHttpClient.newCall(request).enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                callBack.onFailure(Constant.FAILED, Constant.TIME_OUT_EVENT_MSG);
            }

            @Override
            public void onResponse(Call call, Response response) {
                try {
                    String str = response.body().string();
                    LogUtil.d("url = " + url + " ====response = " + str);
                    callBack.onSuccess(str);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

    void postHomeNewsAsync(Map<String, Object> paramsMap, final String url, final ApiCallBack<String> callBack) {
        if (!NetCheckUtil.isNetConnected(mContext)) {
            callBack.onFailure(Constant.NO_NETWORK, Constant.NO_NETWORK_MSG);
            return;
        }
        LogUtil.d("url = " + url);
        //设置body
        JSONObject body = new JSONObject();
//        try {
//            if (null != paramsMap) {
//                for (String key : paramsMap.keySet()) {
//                    if (paramsMap.get(key) instanceof List) {
//                        ArrayList mList = (ArrayList) paramsMap.get(key);
//                        JSONArray array = new JSONArray();
//                        for (Object m : mList) {
//                            array.put(m);
//                        }
//                        body.put(key, array);
//                    } else {
//                        body.put(key, paramsMap.get(key));
//                    }
//                }
//            }
//        } catch (JSONException e) {
//            e.printStackTrace();
//        }

        try {
            if (null != paramsMap) {
                for (String key : paramsMap.keySet()) {
                    Object value = paramsMap.get(key);
                    if (value instanceof List) {
                        ArrayList mList = (ArrayList) value;
                        JSONArray array = new JSONArray();
                        for (Object m : mList) {
                            array.put(m);
                        }
                        body.put(key, array);
                    } else if (value instanceof Map) {
                        body.put(key, new JSONObject((Map) value));
                    } else {
                        body.put(key, value);
                    }
                }
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }


        RequestBody requestBody = RequestBody.create(MediaType.parse(JSON), body.toString());

        Request request = new Request.Builder().url(url).post(requestBody).build();
        LogUtil.d("url = " + url + " ====json = " + body.toString());
        mOkHttpClient.newCall(request).enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                callBack.onFailure(Constant.FAILED, Constant.TIME_OUT_EVENT_MSG);
            }

            @Override
            public void onResponse(Call call, Response response) {
                try {
                    String str = response.body().string();
                    LogUtil.d("url = " + url + " ====response = " + str);
                    callBack.onSuccess(str);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

    /**
     * 将json转key=value的字符串
     *
     * @param jsonObject
     * @return
     */
    private String jsonToStringToMd5(JSONObject jsonObject) {
        StringBuilder stringBuilder = new StringBuilder();
        for (Iterator<String> it = jsonObject.keys(); it.hasNext(); ) {
            String key = it.next();
            if (stringBuilder.length() > 0) {
                stringBuilder.append("&");
            }
            try {
                stringBuilder.append(key).append("=").append(jsonObject.get(key));
            } catch (JSONException e) {
                throw new RuntimeException(e);
            }
        }
        LogUtil.d(" ====token = " + stringBuilder.toString());
        return Utils.md5(stringBuilder.toString());
    }

//    public void getAsync(final String url, final ApiCallBack<String> callBack) {
//        if (!NetCheckUtil.isNetConnected(mContext)) {
//            callBack.onFailure(Constant.NO_NETWORK, Constant.NO_NETWORK_MSG);
//            return;
//        }
//        LogUtil.d("url = " + url);
//        Request request = new Request.Builder().url(url).build();
//        mOkHttpClient.newCall(request).enqueue(new Callback() {
//            @Override
//            public void onFailure(Call call, IOException e) {
//                callBack.onFailure(Constant.FAILED, TIME_OUT_EVENT_MSG);
//            }
//
//            @Override
//            public void onResponse(Call call, Response response) {
//                try {
//                    String str = response.body().string();
//                    LogUtil.d("url = " + url + " ====response = " + str);
//                    callBack.onSuccess(str);
//                } catch (Exception e) {
//                    e.printStackTrace();
//                }
//            }
//        });
//
//    }

//    void postKMap(Map<String, Object> paramsMap, String method, final ApiCallBack<String> callBack) {
//        if (!NetCheck.isNetConnected(mContext)) {
//            callBack.onFailure(Constant.NO_NETWORK, NO_NETWORK_MSG);
//            return;
//        }
//        JSONObject json = new JSONObject();
//        JSONObject body = new JSONObject();
//        int currentTimeMillis = (int) (System.currentTimeMillis() / 1000);
//        try {
//            if (null != paramsMap) {
//                for (String key : paramsMap.keySet()) {
//                    if (paramsMap.get(key) instanceof List) {
//                        ArrayList mList = (ArrayList) paramsMap.get(key);
//                        JSONArray array = new JSONArray();
//                        for (Object m : mList) {
//                            array.put(m);
//                        }
//                        body.put(key, array);
//                    } else {
//                        body.put(key, paramsMap.get(key));
//                    }
//                }
//            }
//            json.put("app_id", Integer.valueOf(DataUtils.getAppId(mContext)));
//            json.put("timestamp",currentTimeMillis);
//            json.put("version", getVersion());
//            json.put("sign", DataUtils.getKMapSign(mContext, currentTimeMillis,getVersion(),BuildConfig.K_MAP_KEY));
//            json.put("data", body);
//        } catch (JSONException e) {
//            e.printStackTrace();
//        }
//        RequestBody requestBody = RequestBody.create(MediaType.parse(JSON), json.toString());
//        final String url;
//        if (method.equals(Api.K_MAP) || method.equals(Api.K_MAP_NEW)) {
//            url = DataUtils.getApiKMapHost(mContext);
//        } else {
//            url = DataUtils.getHost(mContext) + method;
//        }
//        final Request request = new Request.Builder().url(url)
//                .post(requestBody).build();
//        LogUtil.d("url = " + url + " ====json = " + json.toString());
//        mOkHttpClient.newCall(request).enqueue(new Callback() {
//            @Override
//            public void onFailure(Call call, IOException e) {
//                callBack.onFailure(Constant.FAILED, TIME_OUT_EVENT_MSG);
//            }
//
//            @Override
//            public void onResponse(Call call, Response response) {
//                try {
//                    String str = response.body().string();
//                    LogUtil.d("url = " + url + " ====response = " + str);
//                    JSONObject jsonObject = new JSONObject(str);
//                    if (jsonObject.getString("ret").equals("0")) {
//                        callBack.onSuccess(jsonObject.getJSONObject("response").toString());
//                    } else {
//                        String code = "";
//                        try {
//                            JSONObject dataJson = jsonObject.getJSONObject("response").optJSONObject("data");
//                            if (dataJson != null) {
//                                code = dataJson.getString("status_code");
//                            }
//                        } catch (JSONException e) {
//                            e.printStackTrace();
//                        }
//                        if (code == null || code.isEmpty()) {
//                            code = Constant.ERROR;
//                        }
//                        if (code.equals("400") || code.equals("401") || code.equals("402") || code.equals("403") || code.equals("500")) {
//                            getAccessToken(callBack);
//                        } else {
//                            callBack.onFailure(code, jsonObject.getJSONObject("response").getString("message"));
//                        }
//                    }
//                } catch (Exception e) {
//                    e.printStackTrace();
//                    callBack.onFailure(Constant.FAILED, TIME_OUT_EVENT_MSG);
//                }
//            }
//        });
//    }

//    private void getAccessToken(final ApiCallBack<String> callBack) {
//        try {
//            postAsync(null, Api.ACCESS_TOKEN, new ApiCallBack<String>() {
//                int count = 0;
//
//                @Override
//                public void onSuccess(String data) {
//                    Type type = new TypeToken<ApiResponse<Void>>() {
//                    }.getType();
//                    ApiResponse<Void> bean = mGson.fromJson(data, type);
//                    DataUtils.setUserId(mContext, "0");
//                    DataUtils.setToken(mContext, bean.getToken());
//                    callBack.onFailure(Constant.TOKEN_ERROR, TIME_OUT_EVENT_MSG);
//                }
//
//                @Override
//                public void onFailure(String errorCode, String message) {
//                    if (count < 5) {
//                        count++;
//                        postAsync(null, Api.ACCESS_TOKEN, this);
//                    } else {
//                        callBack.onFailure(Constant.FAILED, "token获取失败");
//                    }
//                }
//            });
//        } catch (Exception e) {
//            callBack.onFailure(Constant.FAILED, TIME_OUT_EVENT_MSG);
//            e.printStackTrace();
//        }
//    }

//    void bbsPostAsync(final Map<String, Object> paramsMap, final String method, final ApiCallBack<String> callBack) {
//        if (!NetCheck.isNetConnected(mContext)) {
//            callBack.onFailure(Constant.NO_NETWORK, NO_NETWORK_MSG);
//            return;
//        }
//        JSONObject json = new JSONObject();
//        JSONObject body = null;
//        try {
//            if (paramsMap != null) {
//                body = new JSONObject();
//                for (String key : paramsMap.keySet()) {
//                    body.put(key, paramsMap.get(key));
//                }
//            }
//            long time = System.currentTimeMillis() / 1000;
//            json.put("app_id", APP_ID);
//            json.put("user_id", BBSUtils.getUserId(mContext));
//            json.put("timestamp", time);
//            json.put("sign", BBSUtils.getSign(mContext, time));
//            json.put("data", body);
//        } catch (JSONException e) {
//            e.printStackTrace();
//        }
//        RequestBody requestBody = RequestBody.create(MediaType.parse(JSON), json.toString());
//        final String url = BBSUtils.getHost(mContext) + method;
//        final Request request = new Request.Builder().url(url).post(requestBody).build();
//        LogUtil.d("url = " + url + " ====json = " + json.toString());
//        mOkHttpClient.newCall(request).enqueue(new Callback() {
//            @Override
//            public void onFailure(Call call, IOException e) {
//                callBack.onFailure(Constant.FAILED, TIME_OUT_EVENT_MSG);
//            }
//
//            @Override
//            public void onResponse(Call call, Response response) throws IOException {
//                try {
//                    String result = response.body().string();
//                    LogUtil.d("url = " + url + " ====response = " + result);
//                    JSONObject jsonObject = new JSONObject(result);
//                    String code = jsonObject.optString("Code");
//                    if (code.equals("0")) {
//                        callBack.onSuccess(result);
//                    } else {
//                        if (code.isEmpty()) {
//                            code = Constant.ERROR;
//                        }
//                        if (code.equals("207") || code.equals("208") || code.equals("401") || code.equals("402") || code.equals("403")) {
//                            DataUtils.setUserId(mContext, "0");
//                            DataUtils.setToken(mContext, "");
//                            BBSUtils.clearUser(mContext);
//                        }
//                        callBack.onFailure(code, jsonObject.getString("Message"));
//                    }
//                } catch (Exception e) {
//                    e.printStackTrace();
//                    callBack.onFailure(Constant.FAILED, TIME_OUT_EVENT_MSG);
//                }
//            }
//        });
//    }

//    void upLoadImage(final String method, List<File> fileList, final ApiCallBack<String> callBack) {
//        if (!NetCheck.isNetConnected(mContext)) {
//            callBack.onFailure(Constant.NO_NETWORK, NO_NETWORK_MSG);
//            return;
//        }
//        if (fileList == null) {
//            callBack.onFailure(Constant.FAILED, TIME_OUT_EVENT_MSG);
//            return;
//        }
//        // form 表单形式上传
//        MultipartBody.Builder multipartBody = new MultipartBody.Builder().setType(MultipartBody.FORM);
//        // MediaType.parse() 里面是上传的文件类型。
//
//        for (int i = 0; i < fileList.size(); i++) {
//            if(i == 0){
//                multipartBody.addFormDataPart("front", fileList.get(0).getName(),
//                        RequestBody.create(MediaType.parse("image/jpg"), fileList.get(0)));
//            }else{
//                multipartBody.addFormDataPart("back", fileList.get(1).getName(),
//                        RequestBody.create(MediaType.parse("image/jpg"), fileList.get(1)));
//            }
//        }
////        RequestBody imageBody = RequestBody.create(MediaType.parse("image/jpg"), file);
//        // 参数分别为， 请求key ，文件名称 ， RequestBody
//        long time = System.currentTimeMillis() / 1000;
////        multipartBody.addFormDataPart("uploadfile", file.getName(), imageBody);
//        multipartBody.addFormDataPart("app_id", APP_ID);
//        multipartBody.addFormDataPart("user_id", String.valueOf(DataUtils.getUserId(mContext)));
//        multipartBody.addFormDataPart("timestamp", String.valueOf(time));
//        multipartBody.addFormDataPart("sign", DataUtils.getSign(mContext, time));
//
//        final String url = DataUtils.getHost(mContext) + method;
//        final Request request = new Request.Builder().url(url).post(multipartBody.build()).build();
////        LogUtil.d("url = " + url + " ====json = " + request.body().);
//        mOkHttpClient.newCall(request).enqueue(new Callback() {
//            @Override
//            public void onFailure(Call call, IOException e) {
//                callBack.onFailure(Constant.FAILED, TIME_OUT_EVENT_MSG);
//            }
//
//            @Override
//            public void onResponse(Call call, Response response) throws IOException {
//                try {
//                    String result = response.body().string();
//                    LogUtil.d("url = " + url + " ====response = " + result);
//                    JSONObject jsonObject = new JSONObject(result);
//                    String code = jsonObject.optString("Code");
//                    if (code.equals("0")) {
//                        callBack.onSuccess(result);
//                    } else {
//                        if (code.isEmpty()) {
//                            code = Constant.ERROR;
//                        }
//                        if (code.equals("207") || code.equals("208") || code.equals("401") || code.equals("402") || code.equals("403")) {
//                            BBSUtils.clearUser(mContext);
//                            DataUtils.setUserId(mContext, "0");
//                            DataUtils.setToken(mContext, "");
//                        }
//                        callBack.onFailure(code, jsonObject.getString("Message"));
//                    }
//                } catch (Exception e) {
//                    e.printStackTrace();
//                    callBack.onFailure(Constant.FAILED, TIME_OUT_EVENT_MSG);
//                }
//            }
//        });
//    }

}
